//
// Created by grg on 2020/8/4.
// Copyright (c) 2020 龚任根. All rights reserved.
//

#ifndef TEST_CPP_PROJECT_TEXTVIEW_H
#define TEST_CPP_PROJECT_TEXTVIEW_H

#include "SDL2_ttf/SDL_ttf.h"
#include "stdlib.h"
#include "View.h"
#include "TTFComponent.h"

class TextView : public View {
private:
    TTFComponent *ttf;
    SDL_Color *color;
public:
    TextView(TTFComponent *ttfComponent, int targetZ) : View(targetZ) {
        this->ttf = ttfComponent;
        color = new SDL_Color();
        setColor(0, 0, 0, 255);
    }

    void setColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {
        color->r = r;
        color->g = g;
        color->b = b;
        color->a = a;
    }

    void onEvent(const SDL_Event *event) override {

    }

    void onPreUpdate() override {
//        targetRect
    }

    void kill() override {
        delete this;
    }

protected:
    SDL_Surface *createSurface() override {
        return TTF_RenderText_Solid(ttf->getHyshangweishoushuw(), "", SDL_Color());;
    }

    SDL_Texture *createTexture(SDL_Surface *surface) override {
        return SDL_CreateTextureFromSurface(gContext->getRender(), surface);
    }


};


#endif //TEST_CPP_PROJECT_TEXTVIEW_H
